

/////
// get the weather data ready to merge on 
/////

use "stata data\TOU_demographic 2 lat long", clear 


keep sa lat_all long_all

drop if lat_all == 0
drop if long_all >=0
drop if lat_all < 25

geonear sa  lat lon using "public raw data/stations in 2014 and 2015 hourly weather with lat long", n(stn_call stn_lat stn_lon  ) //this is public data from mesowest for 2014 and 2015 stations along with latitude and longitude
rename nid stn_call
save "stata data\sa to station geomatch 2014-2015 weather data", replace



//reopen consumption data and merge on weather
use  "stata data\A1 PDP 2014 changeover for regs", replace


merge m:1 sa using "stata data\TOU_demographic 2 climate"
keep if _merge == 3
drop _merge


merge m:1 sa using "stata data\sa to station geomatch 2014-2015 weather data"
keep if _merge == 3 
drop _merge


merge m:1 stn_call hour date using "public raw data/Weather data 2014-2015 for merge"

keep if _merge == 3

compress *
drop _merge

drop km_to_nid  lat_all long_all  


save  "stata data\A1 PDP 2014 changeover for regs with weather", replace


